package com.pro.springbootpro.runner;

import com.google.gson.Gson;
import com.pro.springbootpro.entity.People;
import com.pro.springbootpro.mapper.PeopleMapper;
import com.pro.springbootpro.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author DJR (1210843430@qq.com)
 */
@Slf4j
@Component
public class CustomerRunner implements ApplicationRunner {
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private PeopleMapper peopleMapper;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("-----------服务启动时初始化用户信息-----------");
        List<People> peopleList = peopleMapper.getAll();
        redisUtil.set("peoples",new Gson().toJson(peopleList));
        log.info("-----------初始化用户信息结束-----------");
    }
}
